﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ObjectManager;

namespace QuanLyDiem
{
    public partial class frmDiem : Form
    {
        private static frmDiem frm = null;

        private DiemSinhVien DiemSV;

        private frmDiem()
        {
            InitializeComponent();
        }

        public static frmDiem Create()
        {
            return Create(false);
        }

        public static frmDiem Create(bool child)
        {
            if (frm == null)
            {
                frm = new frmDiem();
            }
            if (child)
            {
                frm.ControlBox = false;
                frm.MinimizeBox = false;
                frm.MaximizeBox = false;
                frm.WindowState = FormWindowState.Maximized;
            }
            return frm;
        }

        private void frmDiem_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (frm != null)
            {
                frm.Dispose();
                frm = null;
            }
        }

        private void frmDiem_Load(object sender, EventArgs e)
        {
            
        }

        private void txtMaSV_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnTim.PerformClick();
            }
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            DiemSV = new DiemSinhVien(txtMaSV.Text);
            dgvDiem.DataSource = DiemSV.ListAll();
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            //frmReportDíemSinhVien frm = new frmReportDíemSinhVien((new DiemSinhVien(txtMaSV.Text)).ListAll());
            frmReportDíemSinhVien frm = new frmReportDíemSinhVien((DataTable)dgvDiem.DataSource);
            frm.ShowDialog();
        }

        private void dgvDiem_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {

        }

        private void dgvDiem_CellLeave(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
